package com.cloudcc.boot.enums;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;

public enum YesOrNoEnum {
    /**
     * 是/否枚举类
     */
    YES("是", true),
    NO("否", false);

    // 获取显示名称
    private final String displayName;

    private final boolean booleanValue;

    YesOrNoEnum(String displayName, boolean booleanValue) {
        this.displayName = displayName;
        this.booleanValue = booleanValue;
    }

    @JsonValue
    public String getDisplayName() {
        return displayName;
    }

    // 转换为布尔值
    public boolean toBoolean() {
        return booleanValue;
    }

    // 从布尔值转换
    public static YesOrNoEnum fromBoolean(boolean value) {
        return value ? YES : NO;
    }

    // 从字符串解析（支持中文和英文）
    @JsonCreator
    public static YesOrNoEnum fromString(String value) {
        if (value == null) return null;

        return switch (value.trim().toUpperCase()) {
            case "是", "Y", "YES", "TRUE" -> YES;
            case "否", "N", "NO", "FALSE" -> NO;
            default -> throw new IllegalArgumentException("无效的是/否值: " + value);
        };
    }

}

